Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve description of Callable.bind/unbind #76158

Merged
merged 1 commit into from
Apr 17, 2023

Conversation

AThousandShips
Copy link
Member

@AThousandShips AThousandShips commented Apr 17, 2023

Fixes #76141

@AThousandShips AThousandShips requested a review from a team as a code owner April 17, 2023 07:04
@timothyqiu
Copy link
Member

[b]Note:[/b] This does not remove arguments bound with [method bind].

Technically it does remove arguments bound with bind().

func _ready() -> void:
	# the 42 bound by `bind(42)` is unbound by `unbind(1)`.
	var f := foo.unbind(1).bind(42)
	# so you have to provide exactly one argument here.
	f.call(100)

func foo(a: int) -> void:
	print(a)

The key is that bind() and unbind() are decorators for the argument list provided to its own call() method, producing a new callable. So they are applied backwards when chained.

foo.unbind(1).bind(42).call(100)

call(100) #      argument list is: 100
bind(42)  #             append 42: 100, 42
unbind(1) # remove 1 from the end: 100

foo.bind(88, 99).unbind(1).call(22, 33)

call(22, 33) #      argument list is: 22, 33
unbind(1)    # remove 1 from the end: 22
bind(88, 99) #         append 88, 99: 22, 88, 99

@AThousandShips
Copy link
Member Author

Will add that it doesn't remove arguments previously bound for clarification

@AThousandShips
Copy link
Member Author

AThousandShips commented Apr 17, 2023

Clarified that description and added an example to illustrate it.

(My bad forgot func was a keyword so wanted to avoid it)

doc/classes/Callable.xml Outdated Show resolved Hide resolved
doc/classes/Callable.xml Outdated Show resolved Hide resolved
doc/classes/Callable.xml Outdated Show resolved Hide resolved
@AThousandShips AThousandShips changed the title Improve description of Callable.unbind Improve description of Callable.bind/unbind Apr 17, 2023
doc/classes/Callable.xml Outdated Show resolved Hide resolved
@AThousandShips
Copy link
Member Author

Thank you for your help

@akien-mga akien-mga merged commit 5625399 into godotengine:master Apr 17, 2023
@akien-mga
Copy link
Member

Thanks!

@AThousandShips AThousandShips deleted the unbind_doc branch April 17, 2023 18:16
@AThousandShips
Copy link
Member Author

Thank you!

@YuriSizov
Copy link
Contributor

Cherry-picked for 4.0.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Callable unbind doesn't actually unbind arguments
4 participants